package com.example.changephoto;

import java.io.ByteArrayOutputStream;


import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;


public class MainActivity extends Activity {
    ImageView iv1, iv2, iv3, iv4, iv5, iv6;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        iv1= (ImageView)findViewById(R.id.c42iv1);
        iv2= (ImageView)findViewById(R.id.c42iv2);
        iv3= (ImageView)findViewById(R.id.c42iv3);
        iv4= (ImageView)findViewById(R.id.c42iv4);
        iv5= (ImageView)findViewById(R.id.c42iv5);
        iv6= (ImageView)findViewById(R.id.c42iv6);
        //����ͨ�õ�ͼƬ���������
        OnClickListener listener = new OnClickListener(){
            @Override
            public void onClick(View view) {
                ImageView iv = (ImageView)view;
                int id = view.getId();
                //��ȡImageView��Bitmap����
                Bitmap bm =((BitmapDrawable)iv.getDrawable()).getBitmap();
                //ת���ֽ�����
                byte[] bytes=getBytesOfBitmap(bm);
                Intent intent = new Intent(MainActivity.this, BigImageActivity.class);
                intent.putExtra("bigImage", bytes);
                Bundle bundle = new Bundle();
                startActivity(intent);
            }
        };
        //Ϊ6��ImageViewע����ͬ�ļ�����
        iv1.setOnClickListener(listener);
        iv2.setOnClickListener(listener);
        iv3.setOnClickListener(listener);
        iv4.setOnClickListener(listener);
        iv5.setOnClickListener(listener);
        iv6.setOnClickListener(listener);
    }

    public byte[] getBytesOfBitmap(Bitmap bitmap){
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.WEBP, 0, baos);
        return baos.toByteArray();
    }
}